package com.company.service;

import com.company.utils.MessageResponse;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

public class FileStorageService {
    static Path path = Paths.get("uploads");
    public static MessageResponse<String> save(MultipartFile multipartFile) {
        String message = "";
        try {
            Files.copy(multipartFile.getInputStream(), path.resolve(multipartFile.getOriginalFilename()));
            message = "success";
        } catch (IOException exception) {
            message = "could not storage image";
        }

        return new MessageResponse<>(
                message,
                null
        );
    }

}
